﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CERT.Services.DAL;
using System.Data.Entity;

namespace CERT.Services
{
    public partial class NETServices
    {
      
        public IEnumerable<Lookup> GetAllLookups(System.Linq.Expressions.Expression<Func<Lookup, bool>> predicate)
        {
            using (var context = new NETEntities())
            {
                var entries = context.Lookups.Where(predicate).ToList<Lookup>().AsEnumerable<Lookup>();
                return entries;

            }

        }

        public Lookup GetSingleLookup(System.Linq.Expressions.Expression<Func<Lookup, bool>> predicate)
        {
            using (var context = new NETEntities())
            {
                var entry = ((DbSet<Lookup>)context.Lookups).Include("LookupType").FirstOrDefault<Lookup>(predicate);
                return entry;

            }
        }

        public void DeleteLookup(int id)
        {
            using (var context = new NETEntities())
            {
                var entity = context.Set<Lookup>().FirstOrDefault(a => a.LookupID == id);

                context.Set<Lookup>().Remove(entity);
                context.SaveChanges();
            }

        }

        public void UpdateLookup(Lookup entity)
        {
            try
            {
                using (var context = new NETEntities())
                {
                    context.Entry<Lookup>(entity).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public void AddLookup(Lookup entity)
        {
            using (var context = new NETEntities())
            {
                context.Set<Lookup>().Add(entity);
                context.SaveChanges();
            }

        }
    }
}